home *** CD-ROM | disk | FTP | other *** search
- Unit StrProcs;
-
- (*---------------------------------------------------------------------------*)
- (* *)
- (* This unit contains several utility routines dealing with strings. *)
- (* The routines are used by both the Page2 and Page2Cfg programs. *)
- (* *)
- (* by: R. P. Byrne May 24, 1988 *)
- (* *)
- (* *)
- (* I have placed this unit and it's source code into the public domain *)
- (* in the hope that it may prove useful to someone other than myself. *)
- (* *)
- (* rpb *)
- (* 6/4/88 *)
- (* *)
- (* *)
- (*---------------------------------------------------------------------------*)
-
-
- { --------------------------------------------------------------------------- }
- Interface
- Uses Dos;
- { --------------------------------------------------------------------------- }
-
- Function ToUpper(S : String) : String;
- { Convert a string to all upper case }
-
- Function Copies (C : Char; N : Integer ): String;
- { Create a string containing N copies of the character C }
-
- Function GetToken(Var Source : String; Caps : Boolean) : String;
- { Extract the next token from a string (destructively) }
-
- Function NameOnly(FileName : String) : String;
- { Strip any drive/path information from a file specification }
-
- Function IntStr(Int : Integer; Form : Integer) : String;
- { Convert a word or integer to a string [of length Form] }
-
- Function DateStr : String;
- { Return the current date in string form: Monthname dd, yyyy }
-
- Function Strip(InputStr : String) : String;
- { Remove leading and trailing white space from a string }
-
- { --------------------------------------------------------------------------- }
- Implementation
- { --------------------------------------------------------------------------- }
-
- Function ToUpper(S : String) : String;
- Var
- I : Word;
- Begin
- If Length(S) > 0 then
- For I := 1 to Length(S) do
- S[I] := UpCase(S[I]);
- ToUpper := S;
- End {ToUpper};
-
- { --------------------------------------------------------------------------- }
-
- Function Copies (C : Char; N : Integer ): String;
- Var
- Dest : String;
- I : Integer;
- Begin
- Dest := '';
- If N > 0 then
- For I := 1 to N do
- Dest := Dest + C;
- Copies := Dest;
- End {Copies};
-
- { --------------------------------------------------------------------------- }
-
- Function IsWhite(Ch : Char) : Boolean;
- { This function is internal to the unit and is used by the GetToken and }
- { Strip routines. }
- Begin
- { Space, Tab, LF, CR }
- IsWhite := (Ch in [ #32, #09, #10, #13 ]);
- End {IsWhite};
-
- { --------------------------------------------------------------------------- }
-
- Function IsDelim(Ch : Char) : Boolean;
- { This function is internal to the unit and is used by the GetToken routine }
- Begin
- { Space, Tab, LF, CR, Hyphen, Slash }
- IsDelim := ( Ch in [ #32, #09, #10, #13, #45, #47 ] );
- End {IsDelim};
-
- { --------------------------------------------------------------------------- }
-
- Function GetToken(Var Source : String; Caps : Boolean) : String;
- { Extract next token from a string (destructively) }
- Var
- Token : String;
- I : Integer;
- Begin
- I := 1;
- Token := '';
- If Length(Source) > 0 then begin
- While (IsWhite(Source[I])) and (I <= Length(Source)) do
- I := Succ(I);
- If (I <= Length(Source)) then
- Repeat
- Token := Token + Source[I];
- I := Succ(I);
- Until (IsDelim(Source[I])) or (I > Length(Source));
- If I >= Length(Source) then
- Source := ''
- else
- Delete(Source, 1, I-1);
- end {if};
- If Caps then
- Token := ToUpper(Token);
- GetToken := Token;
- End {GetToken};
-
- { --------------------------------------------------------------------------- }
-
- Function NameOnly(FileName : String) : String;
- { Strip any drive/path information from a file specification }
- Var
- I : Integer;
- Begin
- I := 1;
- While I <= Length(FileName) do
- If (FileName[I] in [':', '\', '/']) then begin
- Delete(FileName, 1, I);
- I := 1
- end {then}
- else
- I := Succ(I);
- NameOnly := FileName;
- End {NameOnly};
-
- { --------------------------------------------------------------------------- }
-
- Function IntStr(Int : Integer; Form : Integer) : String;
- Var
- S : String;
- Begin
- If Form = 0 then
- Str(Int, S)
- else
- Str(Int:Form, S);
- IntStr := S;
- End {IntStr};
-
- { --------------------------------------------------------------------------- }
-
- Function DateStr : String;
- { Return the current date in string form: Monthname dd, yyyy }
- Type
- Str9 = String[9];
- Const
- MonthName : Array[1..12] of Str9 = ('January', 'February', 'March',
- 'April', 'May', 'June', 'July',
- 'August', 'September', 'October',
- 'November', 'December');
- Var
- Regs : Registers;
- Begin
- With Regs do begin
- AH := $2A;
- MsDos(Regs);
- DateStr := MonthName[DH] + ' ' +
- IntStr(DL, 0) + ', ' +
- IntStr(CX, 0);
- end {with};
- End {DateStr};
-
- { -------------------------------------------------------------------------- }
-
- Function Strip(InputStr : String) : String;
- Var
- I, J : Integer;
- Begin
- I := 1;
- While IsWhite(InputStr[I]) and (I < Length(InputStr)) do
- Inc(I);
- J := Length(InputStr);
- While IsWhite(InputStr[J]) and (J > 1) do
- Dec(J);
- If I <= J then
- Strip := Copy(InputStr, I, J - Pred(I))
- else
- Strip := '';
- End {Strip};
-
- { --------------------------------------------------------------------------- }
-
- End {Unit StrProcs}.
-
-